#ifndef _NETBUF_H
#define _NETBUF_H
#include "NetBase.h"

struct SimpleBuf
{
	enum
	{
		BUFF_SIZE = 4096,
	};

	int     nHead;
	int     nTail;
	char    szBUF[BUFF_SIZE];
	void Tidy();
	int GetSpace()const;
	int GetLength()const;
	char* GetHeadBuf();
	char* GetTailBuf();
	void MoveHead(int nCount);
	void MoveTail(int nCount);
	bool Write(const char* pBuf,int nSize);
	bool Read(char* pBuf,int nSize);
	SimpleBuf();
};

class Packet;


class NetBuffer
{
public:
	NetBuffer();
	~NetBuffer();
	WSABUF& GetReceiveBuff();
	WSABUF& GetSendBuff();

	void OnRecived(std::size_t transferred);
	void OnSended(std::size_t transferred);

	void PushBackPacket(Packet* pPacket);
	Packet* PopFrontPacket();
	Packet* PopBackPacket();

private:
	typedef std::deque<Packet*> DEQ_PACKET;
	DEQ_PACKET m_deqPacket;
	My_CriticalSection m_packetCritical;

	WSABUF			  m_wsaBuff;
	SimpleBuf         m_simpleBuff;

};
#endif